package com.young.security.utils;

import com.young.security.entity.LoginUser;
import org.springframework.lang.Nullable;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.Optional;

/**
 * @Author mouyang
 * @Date 2023/09/22 11:41
 **/
public class SecurityFrameworkUtils {

    @Nullable
    public static LoginUser getLoginUser() {
        return Optional.ofNullable(SecurityContextHolder.getContext()).map(SecurityContext::getAuthentication).orElse(null);
    }
}
